const mongoose =require('mongoose');
const {modelName, getAllTestedModel } = require('../models/testedsModel');

async function getAllTested(req,res){
    let result=await getAllTestedModel();
    res.send({
        code:1,
        message:"获取所有已考信息",
        result:result
    })
}

async function getTestResults(req,res){
    let result=await mongoose.model(modelName).find({'testId':req.body._id}).populate('studentId').populate('testId');
    if(result){
        res.send({
            code: 1,
            message: '试卷信息获取成功',
            result: result

        });
    }else{
        res.send({
            code: 0,
            message: '信息获取失败'
        })
    }
}


async function saveTest(req,res){
    let result= await mongoose.model(modelName).create({...req.body});

    if (result) {
        res.send({
            message: "添加成功",
            code: 1
        });
    } else {
        res.send({
            message: "添加失败",
            code: 0
        });
    }
}

module.exports={
    getAllTested,getTestResults,saveTest
}